﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class 数据算法_LCS算法 : System.Web.UI.Page
{
    /// <summary>
    /// 当前的第一个字符串
    /// </summary>
    string strA = "";
    /// <summary>
    /// 当前的第二个字符串
    /// </summary>
    string strB = "";

    

    /// <summary>
    /// 用于得到 web 字符串的文件
    /// </summary>
    Tong.XmlHttp.GetWebData getWebData = new Tong.XmlHttp.GetWebData();
    protected void Page_Load(object sender, EventArgs e)
    {

        strA = getWebData.GetWebDate("http://www.qlili.com/docs/ShowDocs.aspx?id=f46bfc52-b2e3-43b6-a99c-133997fa7ed7&lx=5", "UTF-8");

        strB = getWebData.GetWebDate("http://www.qlili.com/docs/ShowDocs.aspx?id=ae319846-a03a-43a2-9487-578299a2dcba&lx=5", "UTF-8");
        
        ///tt.Text = GetSameString(strA,strB);
        
    }
    /// <summary>
    /// LCS算法救出 当前两个字符串的相同的地方
    /// </summary>
    /// <param name="ArgA"></param>
    /// <param name="ArgB"></param>
    /// <returns></returns>
    public string GetSameString(string ArgA, string ArgB)
    {
        if (String.IsNullOrEmpty(ArgA) || String.IsNullOrEmpty(ArgB)) return String.Empty;
        int[] CompareArr = new int[ArgB.Length];
        int max = 0, maxJ = 0;
        for (int iloop = 0; iloop < ArgA.Length; iloop++)
        {
            for (int jloop = ArgB.Length - 1; jloop >= 0; jloop--)
            {
                //(ArgB[jloop] == ArgA[iloop]) 为显示相等,改为不等于显示不相等的字符串

                CompareArr[jloop] = (ArgB[jloop] == ArgA[iloop]) ? ((iloop == 0 || jloop == 0) ? 1 : CompareArr[jloop - 1] + 1) : 0;
                if (CompareArr[jloop] >= max)
                {
                    max = CompareArr[jloop];
                    maxJ = jloop;
                }
            }
        }
        if (max > 0)
        {
            return ArgB.Substring(maxJ - max + 1, max);
        }
        else return String.Empty;
    }

    /// <summary>
    /// 用于比较两个符串的字典,
    /// 这个字典的长度为 字符串的长度
    /// </summary>
    int[] comparerFrontLength;

    /// <summary>
    /// 
    /// </summary>
    int[] comparerLastLength;

    /// <summary>
    /// 比较两个字符串不同的地方拿出来
    /// </summary>
    /// <param name="tempStrA">要比较的字符串1</param>
    /// <param name="tempStrB">要比较的字符串2</param>
    /// <returns>返回不同的字符串</returns>
    public String ComparerTwoString(string tempStrA, string tempStrB)
    {
        throw new
        Exception  ();
    }


   
}
